<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            从后往前遍历，先初始化result=[[nums[0]]]

            如果nums[i]大于result每一层的元素，那么就更新下一行，不然更新头部
            
            */
            var lengthOfLIS = function (nums) {
                let result = [[nums[0]]]
                for (let i = 1; i < nums.length; i++) {
                    for (let j = result.length - 1; j >= 0; j--) {
                        //result的尾元素
                        let line = result[j]
                        let tail = line[line.length - 1]
                        debugger
                        if (nums[i] > tail) {
                            result[j + 1] = [...line, nums[i]]
                            break
                        } else if (nums[i] < tail && j == 0) {
                            result[j] = [nums[i]]
                        }
                    }
                }
                return result
            }
            console.log(lengthOfLIS([10, 9, 2, 5, 3, 7, 101, 18]))
        </script>
    </body>
</html>
